﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Security;

namespace ASPNETVN.PORTAL.Components.Share.Controls
{
    public partial class ApproveComment : ApproveItemControl
    {

        protected override void OnInit(EventArgs e)
        {
            this.ButtonApprove = btnApprove;
            this.ButtonDelete = btnDelete;
            this.ButtonCancel = btnCancel;
            this.Approve += new EventHandler(ApproveComment_Approve);
            this.Delete += new EventHandler(ApproveComment_Delete);
            base.OnInit(e);
        }

        void ApproveComment_Delete(object sender, EventArgs e)
        {
            Comment.DeleteComment(this.ItemID);
            this.ReturnToReferrerPage();
        }

        void ApproveComment_Approve(object sender, EventArgs e)
        {
            Comment comment = new Comment();
            if (this.ItemID > 0)
            {
                comment = Comment.Load(this.ItemID);
                if (comment != null)
                {
                    comment.Status = true;
                    comment.ApprovedDate = DateTime.Now;
                    comment.ApprovedBy = PortalSecurity.CurrentUser.Identity.Email;
                    comment.Update();
                    this.ReturnToReferrerPage();
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Comment comment = new Comment();
            if (this.ItemID > 0)
            {
                comment = Comment.Load(this.ItemID);
                if (comment != null)
                {
                    LabelBody.Text = Server.HtmlDecode(comment.Body);
                }
            }
        }
    }
}